# -*- encoding: utf-8 -*-
import socket
from threading import Thread

class Client:
    def __init__(self):
        self.client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

    def start(self):
        self.client.connect(("172.20.23.118",8080))
        Thread(target=self.receive,daemon=True).start()

        while True:
           msg = input(">>>")

           if msg == "q":
               break

           self.client.send(msg.encode("utf-8"))

        self.client.close()
        print("Exit.....")

    def receive(self):
        while True:
            recv_msg = self.client.recv(512)

            if recv_msg:
                print("\nSERVER RECV MSG:",recv_msg.decode("utf-8"))
            else:
                print("SERVER 500")
                break

if __name__ == "__main__":
    c = Client()
    c.start()
